<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>
<!-- START 数据表格 -->
<table id="warehouseTable"
       data-toolbar="#toolbar"
       data-pagination="true"
       data-resizable="true"
       data-side-pagination="server"
       data-url="/sea/supply/distribute/findByCnd.do"
       data-page-size="15"
       class="table table-striped table-hover"
>
</table>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload'}){}%>
<script>
    var $warehouseTable = $('#warehouseTable');
    $(function(){

        $(".uploadDetail").hide();
        //START 表格配置
        $warehouseTable.bootstrapTable({
            pageSize:10,
            columns: [
                {
                    title: '预分配柜号',
                    field: 'planNo',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '创建时间',
                    field: 'planCreate',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function() {
                $(".detail-btn").on('click', function () {
                    //详情
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%', '100%'],
                        content: ['/sea/supply/distribute/detail.do?planId=' + id, 'yes']
                    });
                });



                $('.reload-btn').on('click',function(){
                    //详情
                    var id = $(this).attr('data-val');
                    var createId=$(this).attr('data-create');

                    layer.confirm('确定要获取当前柜？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){

                        layer.closeAll();
                        layer.load();
                        $.post('/sea/supply/distribute/reload.do',{planId:id,createId:createId},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    layer.closeAll();
                                    $("#warehouseTable").bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 5000},function () {
                                    layer.closeAll();
                                });
                            }
                        });
                    });
                });

                $('.distribute-btn').on('click',function(){
                    var createId = $(this).attr('data-val');
                    layer.confirm('确定要获取当前柜？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){

                        layer.closeAll();
                        layer.load();
                        $.post('/sea/supply/distribute/getDetail.do',{createId:createId},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    layer.closeAll();
                                    $("#warehouseTable").bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 5000},function () {
                                    layer.closeAll();
                                });
                            }
                        });
                    });
                });
            }
        });
        //END 表格配置

    });
    // 操作菜单
    function optFormatter(value,row){
        var content='';
        if(row.flag==0){
            content+='<button class="distribute-btn btn btn-xs btn-success"  data-val="'+row.createId+'" title="获取分配建议"><i class="fa fa-plus"></i>获取分配建议  </button>&nbsp;';
        }
        content+= '<button class="reload-btn btn btn-xs btn-danger" data-create="'+row.createId+'" data-val="'+row.id+'" title="查看详细"><i class="fa fa-edit"></i> 重新获取分配建议 </button>&nbsp;';
        content+= '<button class="detail-btn btn btn-xs btn-info" data-val="'+row.id+'" title="查看详细"><i class="fa fa-edit"></i> 查看详细 </button>&nbsp;';
        return content;
    }
</script>
</body>
</html>